package com.situ.onlinebookstore.back.controller;

import com.situ.onlinebookstore.back.service.OrderService;
import com.situ.onlinebookstore.common.entity.Admin;
import com.situ.onlinebookstore.common.entity.Order;
import com.situ.onlinebookstore.common.entity.User;
import com.situ.onlinebookstore.common.vo.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController //相当于@Controller与@ResponseBody合并
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {
    private final OrderService orderService;
    @RequestMapping("/search")
    public Result search(Integer page, Integer limit, Order order) {
        if (page == null) {
            return Result.ok(orderService.search(order));
        } else {
            return Result.ok(orderService.searchForPage(page, limit, order));
        }
    }

    @RequestMapping("/edit")
    public Result edit(Order order) {
        //1-接收参数
        try {
            //2-参数校验
            //3-调用Service层
            orderService.edit(order);
            return Result.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }

    }
}
